import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
		{
			path: '/',
			redirect: '/game_hall'
		},{
			name: 'user_login',
			component: () => import('./view/Login/user_login.vue'),
			//component: () => import('./view/Login/login4.vue'),
			meta: {
				title: '玩家登陆页面'
			}
		},{
			name: 'user_register',
			component: () => import('./view/Login/user_register.vue'),
			meta: {
				title: '玩家注册页面'
			}
			
		},{
			name: 'game_hall',
			component: () => import('./view/Game/game_hall.vue'),
			meta: {
				title: '游戏大厅页面'
			}
		},{
			name: 'user',
			component: () => import('./view/user'),
			meta: {
				title: '会员中心'
			}
		},{
			name: 'cart',
			component: () => import('./view/cart'),
			meta: {
				title: '购物车'
			}
		},{
			name: 'goods',
			component: () => import('./view/goods/index.vue'),
			meta: {
				title: '商品详情'
			}
		},
	];

// add route path
routes.forEach(route => {
	route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
	const title = to.meta && to.meta.title;
	if (title) {
		document.title = title;
	}
	next();
});

export { router };